﻿<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:converters='clr-namespace:Shazzam.Converters'
             xmlns:vms='clr-namespace:Shazzam.ViewModels'
             xmlns:commands='clr-namespace:Shazzam.Commands'
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             x:Class="Shazzam.Views.CodeTabView">
  <UserControl.Resources>
    <converters:StringToVisibilityConverter x:Key='visConverter' />
    <converters:VisibiltyToVisibilityConverter x:Key='visvisConverter' />
    <vms:CodeTabViewModel x:Key='codeVM' />
    <LinearGradientBrush x:Key='tabBrush'
                         StartPoint='0,0'
                         EndPoint='1,0'>
      <GradientStop Color='{StaticResource Dark}'
                    Offset='0' />
      <GradientStop Color='{StaticResource Light}'
                    Offset='1' />
    </LinearGradientBrush>
    <Style TargetType="{x:Type TabItem}"
           x:Key='tabItemBackground'>
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="TabItem">
            <Grid>
              <Border Name="Border"
                      Margin="0,0,-4,0"
                      Background="{StaticResource LightBrush}"
                      BorderBrush='{StaticResource LightBrush}'
                      BorderThickness="1,1,1,1"
                      CornerRadius="0,0,0,0">
                <ContentPresenter x:Name="ContentSite"
                                  VerticalAlignment="Center"
                                  HorizontalAlignment="Center"
                                  ContentSource="Header"
                                  Margin="12,2,12,2"
                                  RecognizesAccessKey="True" />
              </Border>
            </Grid>
            <ControlTemplate.Triggers>
              <Trigger Property="IsEnabled"
                       Value="False">
                <Setter TargetName="Border"
                        Property="Background"
                        Value='{StaticResource tabBrush}' />
                <Setter TargetName="Border"
                        Property="BorderBrush"
                        Value='{StaticResource LightBrush}' />
                <Setter Property="Foreground"
                        Value="{StaticResource DarkBrush}" />
              </Trigger>
            </ControlTemplate.Triggers>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>

  </UserControl.Resources>
  <TabControl x:Name='codeTabControl'
              DataContext='{StaticResource codeVM}'
              SnapsToDevicePixels='True'>
    <TabItem x:Name='codeTab'>
      <TabItem.Header>
        <Grid ToolTip='Use Ctrl-F9 to move focus to this tab.'>
          <TextBlock Text="HLSL"
                     x:Name='codeTabHeaderText' />
        </Grid>

      </TabItem.Header>
      <Border BorderBrush='{DynamicResource NeutralDarkBrush}'
              BorderThickness='9'>
        <Border BorderBrush='White'
                BorderThickness='1'>
          <DockPanel MinWidth='330'
                     LastChildFill='True'>

            <StackPanel Orientation="Horizontal"
                        DockPanel.Dock="Bottom"
                        Background="White">

              <TextBlock x:Name='outputTextBox'
                         DockPanel.Dock='Bottom'
                         Margin='5,3,5,8'
                         Padding='8,4'
                         Background='DarkRed'
                         Foreground='White'
                         Visibility='{Binding Text, Converter={StaticResource visConverter}, RelativeSource={RelativeSource Self}}'
                         Text='{Binding ErrorText}'
                         MouseLeftButtonDown='OutputTextBox_MouseLeftButtonDown'
                         ToolTip='Double-click here to goto error.'>

								<TextBlock.Effect>
									<DropShadowEffect BlurRadius='9'
                                    Color='Black'
                                    Direction="335"
                                    Opacity="0.63" />
 								</TextBlock.Effect>
              </TextBlock>
              <TextBlock x:Name='compileStatusText'
                         DockPanel.Dock='Bottom'
                         Background='#FFC4FFC4'
                         Margin='5,3,5,8'
                         Padding='8,4'>
								<TextBlock.Effect>
									<DropShadowEffect BlurRadius='9'
                                    Color='Black'
                                    Direction="335"
                                    Opacity="0.63" />
 								</TextBlock.Effect>
              </TextBlock>
              <TextBlock x:Name='dirtyStatusText'
                         DockPanel.Dock='Bottom'
                         Background='LightYellow'
                         Text='Shader not saved.'
                         Margin='5,3,5,8'
                         Padding='8,4'
                         Visibility="Hidden">
								<TextBlock.Effect>
									<DropShadowEffect BlurRadius='9'
                                    Color='Black'
                                    Direction="335"
                                    Opacity="0.63" />
 								</TextBlock.Effect>
              </TextBlock>
              <TextBlock x:Name='versionNotSupported'
                         Background='#FFE4B85A'
                         Text='PS_3 not available on this computer.'
                         Margin='5,3,5,8'
                         Padding='8,4'
                         Visibility="Hidden">
                            	<TextBlock.Effect>
                            		<DropShadowEffect BlurRadius='9'
                                                  Color='Black'
                                                  Direction="335"
                                                  Opacity="0.63" />
                            	</TextBlock.Effect>
              </TextBlock>
            </StackPanel>
            <DockPanel LastChildFill='True'>
              <WindowsFormsHost x:Name='formsHost'
                                Margin='2,2,2,2' />
            </DockPanel>
          </DockPanel>
        </Border>
      </Border>
    </TabItem>
    <TabItem x:Name='InputControlsTab'
             Visibility='{Binding Visibility, Converter={StaticResource visvisConverter}, ElementName=outputTextBox}'>
      <TabItem.Header>
        <Grid ToolTip='Use Ctrl-F10 to move focus to this tab.'>
          <TextBlock Text="Tryout (adjust settings)" />
        </Grid>

      </TabItem.Header>
      <Border BorderBrush='{DynamicResource NeutralDarkBrush}'
              BorderThickness='9'>
        <Border BorderBrush='White'
                BorderThickness='1'>
          <DockPanel MinWidth='330'
                     LastChildFill='True'
                     Background='{StaticResource NeutralDarkBrush}'>
            <Expander IsExpanded='True'
                      ExpandDirection='Left'
                      DockPanel.Dock='Right'
                      BorderThickness='0'>
              <FlowDocumentScrollViewer Width="300"
                                        BorderThickness="0"
                                        VerticalScrollBarVisibility="Auto"
                                        Background="{StaticResource NeutralDarkBrush}"
                                        Foreground="{StaticResource NeutralWhiteBrush}">
                <FlowDocument FontFamily="Segoe UI"
                              FontSize="12"
                              TextAlignment="Left">
                  <Paragraph>
                    <InlineUIContainer>
                      <Image Source="info.png"
                             Width="24"
                             Height="24" />
                    </InlineUIContainer>
                    <Run Text=" " />
                    <Bold BaselineAlignment="Center">
                      <Run Text="Auto-Generated Control Information" />
                    </Bold>
                  </Paragraph>
                  <Paragraph>
                    <Run Text="Each register declared in HLSL is mapped to a DependencyProperty with a compatible .NET type, as shown in the table below." />
                  </Paragraph>
                  <Table CellSpacing="0"
                         BorderBrush="{StaticResource NeutralWhiteBrush}"
                         BorderThickness="1"
                         Margin="0">
                    <Table.Columns>
                      <TableColumn Width="2*" />
                      <TableColumn Width="3*" />
                    </Table.Columns>
                    <TableRowGroup>
                      <TableRow Background="{StaticResource NeutralDarkBrush}"
                                Foreground="{StaticResource HighlightBrush}">
                        <TableCell Padding="2,1,2,1"
                                   BorderBrush="{StaticResource NeutralWhiteBrush}"
                                   BorderThickness="0,0,0,1">
                          <Paragraph>
                            <Run Text="HLSL type" />
                          </Paragraph>
                        </TableCell>
                        <TableCell Padding="2,1,2,1"
                                   BorderBrush="{StaticResource NeutralWhiteBrush}"
                                   BorderThickness="0,0,0,1">
                          <Paragraph>
                            <Run Text=".NET type" />
                          </Paragraph>
                        </TableCell>
                      </TableRow>
                      <TableRow Background="{StaticResource VeryDarkBrush}">
                        <TableCell Padding="2,1,2,1">
                          <Paragraph>
                            <Run Text="float" />
                          </Paragraph>
                        </TableCell>
                        <TableCell Padding="2,1,2,1">
                          <Paragraph>
                            <Span Foreground="{StaticResource HighlightBrush}">
                              <Run Text="Double" />
                            </Span>
                            <Run Text=" or Single" />
                          </Paragraph>
                        </TableCell>
                      </TableRow>
                      <TableRow Background="{StaticResource NeutralDarkBrush}">
                        <TableCell Padding="2,1,2,1">
                          <Paragraph>
                            <Run Text="float2" />
                          </Paragraph>
                        </TableCell>
                        <TableCell Padding="2,1,2,1">
                          <Paragraph>
                            <Span Foreground="{StaticResource HighlightBrush}">
                              <Run Text="Point" />
                            </Span>
                            <Run Text=" or Size or Vector" />
                          </Paragraph>
                        </TableCell>
                      </TableRow>
                      <TableRow Background="{StaticResource VeryDarkBrush}">
                        <TableCell Padding="2,1,2,1">
                          <Paragraph>
                            <Run Text="float3" />
                          </Paragraph>
                        </TableCell>
                        <TableCell Padding="2,1,2,1">
                          <Paragraph>
                            <Span Foreground="{StaticResource HighlightBrush}">
                              <Run Text="Point3D" />
                            </Span>
                            <Run Text=" * or Vector3D*" />
                          </Paragraph>
                        </TableCell>
                      </TableRow>
                      <TableRow Background="{StaticResource NeutralDarkBrush}">
                        <TableCell Padding="2,1,2,1">
                          <Paragraph>
                            <Run Text="float4" />
                          </Paragraph>
                        </TableCell>
                        <TableCell Padding="2,1,2,1">
                          <Paragraph>
                            <Span Foreground="{StaticResource HighlightBrush}">
                              <Run Text="Color" />
                            </Span>
                            <Run Text=" or Point4D*" />
                          </Paragraph>
                        </TableCell>
                      </TableRow>
                    </TableRowGroup>
                  </Table>
                  <Paragraph Margin="0,2,0,0"
                             FontSize="11">
                    <Run Text="* Available in WPF but not in Silverlight." />
                  </Paragraph>
                  <Paragraph>
                    <Run Text="The highlighted types are used by default, but other compatible types can be selected in the comments before an HLSL register declaration:" />
                  </Paragraph>
                  <Paragraph Padding="2"
                             Background="White"
                             Foreground="Black"
                             FontFamily="Consolas">
                    <Span Foreground="Green">
                      <Run Text="/// &lt;summary&gt;Input size&lt;/summary&gt;" />
                      <LineBreak />
                      <Run Text="/// " />
                      <Run Background="#60FFC000"
                           Text="&lt;type&gt;Size&lt;/type&gt;" />
                      <LineBreak />
                      <Run Text="/// &lt;minValue&gt;10,10&lt;/minValue&gt;" />
                      <LineBreak />
                      <Run Text="/// &lt;maxValue&gt;100,100&lt;/maxValue&gt;" />
                      <LineBreak />
                      <Run Text="/// &lt;defaultValue&gt;3,3&lt;/defaultValue&gt;" />
                    </Span>
                    <LineBreak />
                    <Run Foreground="Maroon"
                         FontWeight="Bold"
                         Text="float2" />
                    <Run Text=" InputSize : " />
                    <Run Foreground="Blue"
                         FontWeight="Bold"
                         Text="register" />
                    <Run Text=" (C0);" />
                  </Paragraph>
                </FlowDocument>
              </FlowDocumentScrollViewer>
            </Expander>
            <ScrollViewer HorizontalScrollBarVisibility='Disabled'
                          VerticalScrollBarVisibility='Visible'>
              <StackPanel x:Name='inputControlPanel'
                          VerticalAlignment='Top'
                          HorizontalAlignment='Left'
                          Margin='2,2,2,2'
                          Background='{StaticResource NeutralDarkBrush}' />
            </ScrollViewer>
          </DockPanel>
        </Border>
      </Border>
    </TabItem>
    <TabItem IsEnabled='False'
             Header='   '
             Style='{StaticResource tabItemBackground}'>

    </TabItem>
    <TabItem x:Name='csharpTab'
             Header='Generated Shader - C#'
             Visibility='{Binding Visibility, Converter={StaticResource visvisConverter}, ElementName=outputTextBox}'>
      <Border BorderBrush='{DynamicResource NeutralDarkBrush}'
              BorderThickness='9'>
        <Border BorderBrush='White'
                BorderThickness='1'>
          <DockPanel MinWidth='330'
                     LastChildFill='True'>
            <WindowsFormsHost x:Name='formsHostCs'
                              Margin='2,2,2,2' />
          </DockPanel>
        </Border>
      </Border>
    </TabItem>
    <TabItem x:Name='vbTab'
             Header='Generated Shader - Visual Basic'
             Visibility='{Binding Visibility, Converter={StaticResource visvisConverter}, ElementName=outputTextBox}'>
      <Border BorderBrush='{DynamicResource NeutralDarkBrush}'
              BorderThickness='9'>
        <Border BorderBrush='White'
                BorderThickness='1'>
          <DockPanel MinWidth='330'
                     LastChildFill='True'>
            <WindowsFormsHost x:Name='formsHostVb'
                              Margin='2,2,2,2' />
          </DockPanel>
        </Border>
      </Border>
    </TabItem>

  </TabControl>
</UserControl>
